<?php

class LoginAction extends AppBaseAction
{
	public function index()
	{
		$this->t();
	}
	
	public function checklogin()
	{
		if(isset($_POST['email']) && isset($_POST['password'])) {
			$status = AccountService::checkLogin(array('email'=>$_POST['email'],'password'=>md5($_POST['password'])));
			if(isset($status['uid'])){
				AccountService::setSession($status['uid']);
				//redirect to home page
				$this->redirect('index/home');
			}else{
				$msg = ($status['status']==2) ? '帐号密码错误' : '帐号已被禁用';
				$this->redirect('login/index',array('msg'=>urlencode($msg)));
			}
		}
	}
	
	public function image()
	{
		$img = new Captcha();
		$img->generate();
	}
	
	public function logout()
	{
		//do logout 
		$id = $this->uid;
		AccountService::endSession($id);
		//jump to the page
		$this->redirect('login/index',array('msg'=>urlencode('您已退出成功！')));
	}
}